<?php


namespace App\Models\Admin;


class AdminShopOrderList extends Base
{
    protected $table = 'admin_shop_order_list';
    protected $guarded = [];
    protected $dateFormat = 'U';

    public function dev()
    {
        return $this->belongsTo(AdminDev::class,'dev_id','id');
    }

    public static function getInfoByOid($oid=0)
    {
        $info=self::with([
            'dev:id,pic'
        ])
            ->where('oid',$oid)
            ->get()
        ->transform(function ($item,$key)
        {
            $item->pic=is_null($item->dev)?'':$item->dev->pic;
            $item->order_item_money=sprintf("%.2f",round($item->order_num*$item->order_price,2));
            $item->sort_money=sprintf("%.2f",round($item->sort_num*$item->sort_price,2));
            unset($item->dev);

            return $item;
        });
        return $info;
    }

}
